<template>
  <header>
        <button @click="$router.go(-1)" class="back-button">&lt;</button>
        <h1>下载宇宙银行APP</h1>
        <button class="more-button">···</button>
      </header>
  <div class="app-container">
    <div class="button-container">
      <button class="button download-button" @click="downloadFile">下载APP</button>
      <button class="button open-button" @click="openApp">打开APP</button>
    </div>
  </div>
</template>

<script>
export default {
  name: 'App',
  methods: {
    downloadFile() {
      try {
        const fileUrl = this.getAssetUrl('app.gif');
        this.triggerDownload(fileUrl);
      } catch (error) {
        this.handleError('下载文件时出错:', error);
      }
    },
    openApp() {
      try {
        const appUrl = this.getAssetUrl('app.gif');
        window.location.href = appUrl; // 打开APP
      } catch (error) {
        this.handleError('打开APP时出错:', error);
      }
    },
    getAssetUrl(fileName) {
      return `../assets_page2/${fileName}`;
    },
    triggerDownload(url) {
      const link = document.createElement('a');
      link.href = url;
      link.download = 'app.gif'; // 设置下载文件的名称
      link.style.display = 'none'; // 隐藏链接
      document.body.appendChild(link);
      link.click();
      document.body.removeChild(link);
    },
    handleError(message, error) {
      console.error(message, error);
    }
  }
}
</script>

<style scoped>
header {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

h1 {
  padding: 0 20px;
  font-size: 20px;
  color: #444;
}

.back-button {
  position: absolute;
  left: 15px;
  font-size: 24px;
  background: none;
  border: none;
  cursor: pointer;
}

.more-button {
  position: absolute;
  right: 0;
  font-size: 24px;
  background: none;
  border: none;
  cursor: pointer;
}

.app-container {
  background: url('../page2/assets_page2/background.svg') center/cover no-repeat;
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  position: relative;
}

.button-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  position: absolute;
  top: 75%; /* 将按钮容器放在页面的 3/4 高度 */
  transform: translateY(-50%); /* 使容器居中 */
}

.button {
  width: 120px;
  height: 50px;
  border-radius: 20px;
  border: none;
  font-size: 16px;
  cursor: pointer;
}

.download-button {
  background-color: #7ED321;
  color: white;
}

.open-button {
  background-color: white;
  color: #666666;
  border: 1px solid #CCC;
  margin-top: 20px; /* 增加按钮之间的垂直间距 */
}
</style>
